package personal.hrsw1.demo1.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import personal.hrsw1.demo1.domain.Goods;
import personal.hrsw1.demo1.service.GoodsService;

import java.util.List;

@Controller
@RequestMapping("/goods")
public class GoodsController {

    private static final Logger logger = LoggerFactory.getLogger(GoodsController.class);

    @Autowired
    GoodsService goodsService;

    @RequestMapping("list")
    public String list(Model model) {
        List<Goods> goods = goodsService.selectAll();
//        if (goods == null || goods.isEmpty()) {
//            logger.info("查询到的商品数据为空");
//        } else {
//            logger.info("查询到的商品数据数量: {}", goods.size());
//        }
        model.addAttribute("goods", goods);
        return "listGoods";
    }
}